"use strict";
cc._RF.push(module, '975e2GeUTlPT4Fhoh9nSW/X', 'levelFindSpriteAnswerNode');
// scripts/modes/normalMode/levelFindSprite/base/levelFindSpriteAnswerNode.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../../../engines/gameEngine");
var Drag_1 = require("../../baseScript/Drag");
var levelFindSpriteBase_1 = require("./levelFindSpriteBase");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var levelFindSpriteAnswerNode = /** @class */ (function (_super) {
    __extends(levelFindSpriteAnswerNode, _super);
    function levelFindSpriteAnswerNode() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.levelScript = null;
        _this.nameNode = null;
        _this.circleNode = null;
        _this.isAnswer = false;
        _this.minMultiple = 0.9;
        _this.isneedScale = true;
        _this.sound = "";
        /** 对应标签 */
        _this.tagNum = 0;
        /** 是否已经回答 */
        _this.isOk = false;
        _this.startCount = false;
        _this.startTouchTime = 0;
        _this.startTouchPos = cc.Vec2.ZERO;
        return _this;
    }
    levelFindSpriteAnswerNode.prototype.onLoad = function () {
        _super.prototype.onLoad.call(this);
        var answer = this.node.getChildByName("answer");
        this.nameNode = answer.getChildByName("nameFrame");
        this.circleNode = answer.getChildByName("quan");
        this.init();
    };
    levelFindSpriteAnswerNode.prototype.init = function () {
        this.circleNode.active = false;
        this.nameNode.active = false;
    };
    levelFindSpriteAnswerNode.prototype.update = function (dt) {
        var _this = this;
        if (this.startCount) {
            this.startTouchTime += dt;
            if (this.startTouchTime >= 1) {
                this.startTouchTime = 0;
                if (this.sound != "") {
                    gameEngine_1.default.getManagers().soundMgr.playSound(this.sound);
                }
                if (this.isOk) {
                    return;
                }
                this.levelScript.currentOkNum++;
                this.isOk = true;
                gameEngine_1.managers().soundMgr.playSound('mainSound/hcy1'); // 正确音效
                gameEngine_1.managers().soundMgr.playVibrate();
                // 显示答案节点
                this.levelScript.addOneAnswer(this.tagNum);
                // let daanString: string = "daan_" + this.tagNum;
                // this.levelScript.DaAnNode.getChildByName(daanString).active = true;
                // this.node.getChildByName("daan_quan").active = true;
                this.circleNode.active = true;
                this.nameNode.active = true;
                this.scheduleOnce(function () {
                    _this.nameNode.active = false;
                }, 2);
                this.startCount = false;
                console.log("数量：", this.levelScript.currentOkNum, "需求数量：", this.levelScript.needCount);
                if (this.levelScript.currentOkNum == this.levelScript.needCount) {
                    this.levelScript.isPlaySound = true;
                    this.levelScript.winAni().then(function () {
                        _this.levelScript.Win(2);
                    });
                }
            }
        }
    };
    levelFindSpriteAnswerNode.prototype.moveComponentStart = function (touchEvent) {
        if (!this.isAnswer)
            return;
        if (this.levelScript.AMPNode.scale < this.minMultiple)
            return;
        gameEngine_1.managers().soundMgr.playVibrate();
        touchEvent.stopPropagation();
        if (this.isneedScale)
            this.node.scale = 1.2;
        this.startCount = true;
        if (this.levelScript.isPlaySound)
            return;
        if (this.isOk)
            return;
        if (!this.isAnswer)
            return;
        this.startTouchPos = touchEvent.getLocation();
        var nextPos = this.node.parent.convertToNodeSpaceAR(this.startTouchPos);
        /** 跟随移动 */
        // this.node.setPosition(cc.v2(nextPos.x, nextPos.y));
    };
    levelFindSpriteAnswerNode.prototype.moveComponent = function (touchEvent) {
        // touchEvent.stopPropagation();
        // if (this.levelScript.isPlaySound) return;
        // if (this.isOk) return;
        // let touches = touchEvent.getTouches();
        // let touchPos: cc.Vec2 = touchEvent.getLocation();
        // let distance = Math.sqrt((touchPos.y - this.startTouchPos.y) * (touchPos.y - this.startTouchPos.y) + (touchPos.x - this.startTouchPos.x) * (touchPos.x - this.startTouchPos.x));
        // let nextPos: cc.Vec2 = this.node.parent.convertToNodeSpaceAR(touchPos);
        // if (this.startTouchTime > 1) {
        //     this.levelScript.currentOkNum++;
        //     let daanString: string = "daan_" + this.tagNum;
        //     this.levelScript.DaAnNode.getChildByName(daanString).active = true;
        //     this.levelScript.DaAnNode.getChildByName(daanString).getChildByName("daan_quan").active = true;
        // }
        /** 跟随移动 */
        // this.node.setPosition(cc.v2(nextPos.x, nextPos.y));
    };
    levelFindSpriteAnswerNode.prototype.moveComponentEnd = function (touchEvent) {
        if (this.isneedScale)
            this.node.scale = 1;
        touchEvent.stopPropagation();
        this.startCount = false;
        this.startTouchTime = 0;
        if (this.levelScript.isPlaySound)
            return;
        if (this.isOk)
            return;
        if (!this.isAnswer)
            return;
        var touchPos = touchEvent.getLocation();
        var nextPos = this.node.parent.convertToNodeSpaceAR(touchPos);
        var distance = Math.sqrt((touchPos.y - this.startTouchPos.y) * (touchPos.y - this.startTouchPos.y) + (touchPos.x - this.startTouchPos.x) * (touchPos.x - this.startTouchPos.x));
    };
    __decorate([
        property({ type: levelFindSpriteBase_1.default, displayName: "关卡脚本" })
    ], levelFindSpriteAnswerNode.prototype, "levelScript", void 0);
    __decorate([
        property({ displayName: "是否是答案节点" })
    ], levelFindSpriteAnswerNode.prototype, "isAnswer", void 0);
    __decorate([
        property({ displayName: "需要放大多少倍才能被点击" })
    ], levelFindSpriteAnswerNode.prototype, "minMultiple", void 0);
    __decorate([
        property({ displayName: "是否需要点击放大" })
    ], levelFindSpriteAnswerNode.prototype, "isneedScale", void 0);
    __decorate([
        property()
    ], levelFindSpriteAnswerNode.prototype, "sound", void 0);
    __decorate([
        property({ type: cc.Integer, displayName: "对应标签" })
    ], levelFindSpriteAnswerNode.prototype, "tagNum", void 0);
    levelFindSpriteAnswerNode = __decorate([
        ccclass
    ], levelFindSpriteAnswerNode);
    return levelFindSpriteAnswerNode;
}(Drag_1.default));
exports.default = levelFindSpriteAnswerNode;

cc._RF.pop();